How to get exit code in CDM

Categories: Scripts; Tagged with: ; @ January 14th, 2013 15:18

Requirement:

Need to catch the exit code, handle the Error based on the exit code.

Solution:

Use %ErrorLevel% – Almost all applications will set an exit code when complete (by conversion, 0 means successful).

 

Example 1:
copy file1.txt file3.txt
ECHO ...%ErrorLevel%

copy fileNotExisting.txt f.txt
ECHO %ErrorLevel%

Output:

“1 file(s) copied”
0

“The system cannot find the file specified.”
1

 

Example 2:

SET SSIS_EXIT_CODE=%ErrorLevel%
copy "%PKG_PATH%\Logs\….dtsx.log" ..
IF %SSIS_EXIT_CODE% NEQ 0 (
    EXIT /B %SSIS_EXIT_CODE%
)

 

Links:

http://ss64.com/nt/errorlevel.html
http://ss64.com/nt/exit.html

How to check the exit code of the last command in batch file?

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.